﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
interface getArea
{
    double getarea();
}
abstract class shape:getArea
{
    public abstract bool correct();
    public abstract double getarea();
}
class rectangle : shape
{
    public int a, b;
    public rectangle()
    {
        a = b = 0;
    }
    public rectangle(int a,int b)
    {
        this.a = a;
        this.b = b;
    }

    public override bool correct()
    {
        if (a>0&&b>0)
        {
            return true;
        }
        return false;
    }

    public override double getarea()
    {
        return a * b;
    }
    
}
class Squar:rectangle
{
    public Squar(int a)
    {
        this.a = this.b = a;
    }
    public override bool correct()
    {
        if (a==b && a>0)
        {
            return true;
        }
        return false;
    }
}
class triangle:shape
{
    public int a, b, c;
    public triangle()
    {
        a = b = c = 0;
    }
    public triangle(int a,int b,int c)
    {
        this.a = a;
        this.b = b;
        this.c = c;
    }
    public override bool correct()
    {
        return a + b > c && a + c > b && b + c > a;
    }
    public override double getarea()
    {
        double s = (a + b + c) / 2;  // 计算半周长
        return Math.Sqrt(s * (s - a) * (s - b) * (s - c));
    }
}
class Program
{
    static void Main(string[] args)
    {
        rectangle rect = new rectangle(5, 10);
        Console.WriteLine($"长方形: 宽 = {rect.a}, 高 = {rect.b}, 面积 = {rect.getarea()}, 合法 = {rect.correct()}");
        Squar s = new Squar(5);
        Console.WriteLine($"正方形: 边长 = {s.a}, 面积 = {s.getarea()}, 合法 = {s.correct()}");
        triangle triangle = new triangle(3, 4, 5);
        Console.WriteLine($"三角形: 边长 = {triangle.a}, {triangle.b}, {triangle.c}, 面积 = {triangle.getarea():F2}, 合法 = {triangle.correct()}");
        triangle invalidTriangle = new triangle(1, 2, 3);
        Console.WriteLine($"无效三角形: {invalidTriangle.correct()}");
    }
}

